package BanyuanClub.Study.Day0308;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 线程的Callable写法
 */
public class MyCallable implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        return sum;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> ft = new FutureTask<>(new MyCallable());
        Thread th = new Thread(ft);
        th.start();
        //get会造成阻塞
        System.out.println(ft.get());
        System.out.println("qqqqqq");
    }
}
